package com.hifar.test.api.constant;

/**
 * 员工数据验证错误码枚举
 * 用于标准化员工数据验证错误信息
 */
public enum EmployeeValidationErrorCode {
    
    // 请求数据相关错误
    NULL_DATA_REQUEST("EMP_001", "数据请求为空", "请检查请求体是否为空"),
    NULL_MODEL_CODE("EMP_002", "模型代码为空", "请检查modelCode字段是否为空"),
    INVALID_MODEL_CODE("EMP_003", "模型代码错误", "modelCode必须为'EMPLOYEE'"),
    NULL_DATA_STATUS("EMP_004", "数据状态为空", "请检查dataStatus字段是否为空"),
    NULL_DATA_LIST("EMP_005", "数据列表为空", "请检查data字段是否为空或空数组"),
    
    // 数据项相关错误
    NULL_DATA_ITEM("EMP_006", "数据项为空", "数据列表中存在空的数据项"),
    NULL_EMPLOYEE_INFO("EMP_007", "员工信息为空", "数据项中缺少员工信息"),
    
    // 员工基本信息错误
    NULL_USER_CODE("EMP_008", "用户编号为空", "userCode字段不能为空"),
    EMPTY_USER_CODE("EMP_009", "用户编号为空字符串", "userCode字段不能为空字符串"),
    NULL_ID_NAME("EMP_010", "用户姓名为空", "idName字段不能为空"),
    EMPTY_ID_NAME("EMP_011", "用户姓名为空字符串", "idName字段不能为空字符串"),
    
    // 联系方式错误
    INVALID_TELEPHONE("EMP_012", "电话号码格式错误", "telephone字段格式不正确"),
    INVALID_MOBILE("EMP_013", "手机号码格式错误", "mobile字段格式不正确"),
    INVALID_EMAIL("EMP_014", "邮箱格式错误", "email字段格式不正确"),
    
    // 安全级别错误
    INVALID_SECURITY_LEVEL("EMP_015", "安全级别错误", "securityLevel必须在1-5之间"),
    INVALID_SECURITY_LEVEL_FORMAT("EMP_016", "安全级别格式错误", "securityLevel必须是数字格式"),
    
    // 密级错误
    INVALID_SECRET_LEVEL("EMP_017", "密级错误", "secretLevel必须在1-5之间"),
    NULL_SECRET_LEVEL("EMP_018", "密级为空", "secretLevel字段不能为空"),
    
    // 部门信息错误
    NULL_DEPT_ID("EMP_019", "部门ID为空", "deptId字段不能为空"),
    EMPTY_DEPT_ID("EMP_020", "部门ID为空字符串", "deptId字段不能为空字符串"),
    
    // IP地址错误
    INVALID_IP_ADDRESS("EMP_021", "IP地址格式错误", "ip字段格式不正确"),
    
    // 业务规则错误
    DUPLICATE_USER_CODE("EMP_022", "用户编号重复", "userCode已存在，不能重复"),
    INVALID_JOB_CODE("EMP_023", "工号格式错误", "jobCode字段格式不正确"),
    INVALID_ROW_SORT("EMP_024", "排序字段错误", "rowSort字段必须是数字"),
    
    // 系统错误
    VALIDATION_SYSTEM_ERROR("EMP_025", "验证系统错误", "数据验证过程中发生系统异常"),
    DATABASE_ERROR("EMP_026", "数据库错误", "数据库操作失败"),
    BUSINESS_RULE_ERROR("EMP_027", "业务规则错误", "数据不符合业务规则");
    
    private final String code;
    private final String message;
    private final String suggestion;
    
    EmployeeValidationErrorCode(String code, String message, String suggestion) {
        this.code = code;
        this.message = message;
        this.suggestion = suggestion;
    }
    
    public String getCode() {
        return code;
    }
    
    public String getMessage() {
        return message;
    }
    
    public String getSuggestion() {
        return suggestion;
    }
    
    /**
     * 创建错误响应对象
     */
    public EmployeeValidationErrorResponse createErrorResponse() {
        return new EmployeeValidationErrorResponse(this);
    }
    
    /**
     * 员工数据验证错误响应类
     */
    public static class EmployeeValidationErrorResponse {
        private String code;
        private String message;
        private String suggestion;
        private long timestamp;
        private String fieldName;
        private Object fieldValue;
        
        public EmployeeValidationErrorResponse(EmployeeValidationErrorCode errorCode) {
            this.code = errorCode.getCode();
            this.message = errorCode.getMessage();
            this.suggestion = errorCode.getSuggestion();
            this.timestamp = System.currentTimeMillis();
        }
        
        public EmployeeValidationErrorResponse(EmployeeValidationErrorCode errorCode, String fieldName, Object fieldValue) {
            this(errorCode);
            this.fieldName = fieldName;
            this.fieldValue = fieldValue;
        }
        
        // Getters and Setters
        public String getCode() {
            return code;
        }
        
        public void setCode(String code) {
            this.code = code;
        }
        
        public String getMessage() {
            return message;
        }
        
        public void setMessage(String message) {
            this.message = message;
        }
        
        public String getSuggestion() {
            return suggestion;
        }
        
        public void setSuggestion(String suggestion) {
            this.suggestion = suggestion;
        }
        
        public long getTimestamp() {
            return timestamp;
        }
        
        public void setTimestamp(long timestamp) {
            this.timestamp = timestamp;
        }
        
        public String getFieldName() {
            return fieldName;
        }
        
        public void setFieldName(String fieldName) {
            this.fieldName = fieldName;
        }
        
        public Object getFieldValue() {
            return fieldValue;
        }
        
        public void setFieldValue(Object fieldValue) {
            this.fieldValue = fieldValue;
        }
        
        @Override
        public String toString() {
            return "EmployeeValidationErrorResponse{" +
                    "code='" + code + '\'' +
                    ", message='" + message + '\'' +
                    ", suggestion='" + suggestion + '\'' +
                    ", timestamp=" + timestamp +
                    ", fieldName='" + fieldName + '\'' +
                    ", fieldValue=" + fieldValue +
                    '}';
        }
    }
}
